//
//  BiSaleExecuteListViewController.m
//  TrunkIndustryManageSystem
//
//  Created by WT_lyy on 15/4/21.
//  Copyright (c) 2015年 李璐西. All rights reserved.
//

#import "BiSaleListViewController.h"
#import "SaleListCell.h"
#import "BiCarSaleCheckEntity.h"
@interface BiSaleListViewController ()<UITableViewDataSource,UITableViewDelegate>{

    UITableView * _tableView;
    
    NSMutableArray * _saleExecuteList;
}

@end

@implementation BiSaleListViewController

- (id)init
{
    self = [super init];
    if (self)
    {
        _saleExecuteList = [[NSMutableArray alloc] init];
    }
    return self;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
   
    [self setNavBackBtn];
    
    [self setNavBarTitle:@"行销执行列表"];
    
    [self setNavBarWithHidden:NO];
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, [self viewTop], MAIN_SCREEN_WIDTH, MAIN_SCREEN_HEIGHT-[self viewTop])];
    
    _tableView.delegate = self;
    
    _tableView.dataSource = self;
    
    [self.view addSubview:_tableView];
    
    _tableView.rowHeight = 80;
    
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    NSDictionary * paraDic = [NSDictionary dictionaryWithObjectsAndKeys:[BiUserEntity sharedInstance].userid,@"userId",
                              [NSNumber numberWithInt:0],@"page",
                             [NSNumber numberWithInt:10],@"pageSize",
                              [NSNumber numberWithInt:0],@"status",
                              nil];
   // NSString *url = [NSString stringWithFormat:@"%@/erp/mobile.php/CarXingxiao/getList", SERVICE_URL];
    //[self sethttpRequestFormat:url Tag:0 Data:[[self sendJson:paraDic] dataUsingEncoding:NSUTF8StringEncoding]];
    
    [[BiNetEngine shareInstance] requestCarSaleCheckList:self paraDict:paraDic];
    
    [self asyshowHUDView:WAITING CurrentView:self];
    
    
}

//- (void)requestFinished:(ASIHTTPRequest *)request{
//    [super requestFinished:request];
//    NSString *responseStr = [request responseString];
//    
//    NSDictionary *jsonDict = [responseStr objectFromJSONStringWithParseOptions:JKParseOptionLooseUnicode];
//}

#pragma -mark UitabeViewDelegate 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}

#pragma -mark UitabeViewDatasource

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

//    if (_saleExecuteList) {
//        
//        return _saleExecuteList.count;
//    }
    
    return 4;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString * myIndentifier = @"SaleListCell";
    
    SaleListCell * cell = (SaleListCell *)[tableView dequeueReusableCellWithIdentifier:myIndentifier];
    
    if (!cell)
    {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"SaleListCell" owner:self options:nil] firstObject];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        
    }
    
//    BiCarSaleCheckEntity * entity = [_saleExecuteList objectAtIndex:indexPath.row];
//    
//    cell.labApplyer.text = entity.name;
//    
//    cell.labDes.text = entity.destination;
//    
//    cell.labTime.text = entity.gooff_time;

    return cell;
}

#pragma -mark Net Delegate
- (void)onNetEngineResponse:(int)tag entity:(id)entity userInfo:(NSDictionary *)userInfo
{
    
    [self removeHUDView:self];
    
    NSArray * array = (NSArray *)entity;
    
    if (1 == array.count) {
        
        BiCarSaleCheckEntity *  entity_ = [array firstObject];
        
        if ([entity_.responseStatus integerValue]!= 200) {
            
            [self showMessage:entity_.resultinfo];
            
            return;
        }else{
        
            [_saleExecuteList removeAllObjects];
            
            [_saleExecuteList addObjectsFromArray:array];
            
            [_tableView reloadData];
        }
    }else{
        
        [_saleExecuteList addObjectsFromArray:array];
        
        [_tableView reloadData];
        
    }
    
}
- (void)onNetEngineResponseFail:(int)tag entity:(id)entity userInfo:(NSDictionary *)userInfo
{
    [self removeHUDView:self];
}

@end
